﻿//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Mapping Application Block
//===============================================================================

using System;
using System.Collections.Generic;
using EntLibContrib.Query;

namespace EntLibContrib.Mapping.QuickStart.DomainObjects
{
	public abstract class OwnerDomainBase : DomainBase
	{
		#region Fields
		private Guid ownerId;
		private Owner owner;
		#endregion

		#region Properties
		[Map()]
		public Guid OwnerId
		{
			get { return ownerId; }
			set
			{
				ownerId = value;
				IsDirty = true;
			}
		}

		public Owner Owner
		{
			get
			{
				if (owner == null)
				{
					if (ownerId != Guid.Empty)
					{
						IDictionary<string, object> parameters = new Dictionary<string, object>();
						parameters.Add("Id", ownerId);
						owner = MapperFactory.CreateMapper("Owner Mapper").ToDomainObject<Owner>(QueryFactory.CreateQuery("Read Owner By Id").ExecuteForRead(parameters));
					}
				}

				return owner;
			}
		}
		#endregion

		#region Construction
		protected OwnerDomainBase()
		{ }
		#endregion
	}
}
